<template>
  <div
    class="fixed-bottom-btn"
    :class="{'has-sidebar': !sidebarHide}"
    :style="{
      zIndex: zIndex,
      '--bottom-height': bottomHeight + 'px'
    }"
  >
    <div class="btn-wrapper">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'FixedBottomButton',
  props: {
    // 层级
    zIndex: {
      type: Number,
      default: 2000
    }
  },
  data() {
    return {
      initLoaded: false,
      bottomHeight: 64 // 按钮区域总高度(包含padding)
    }
  },
  computed: {
    ...mapState({
      sidebar: state => state.app.sidebar
    }),
    sidebarHide() {
      return this.sidebar.hide
    }
  },
  mounted() {
    // 添加底部padding
    document.querySelector('.app-container').style.paddingBottom = this.bottomHeight + 10 + 'px';
    this.initLoaded = true
  },
  beforeDestroy() {
    // 组件销毁时移除padding
    document.querySelector('.app-container').style.paddingBottom = ''
  }
}
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/variables.scss";

.fixed-bottom-btn {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--bottom-height);
  background-color: rgba(255, 255, 255, 0.98); // 半透明白色背景
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08); // 顶部阴影
  backdrop-filter: blur(10px); // 毛玻璃效果
  // 有侧边栏时的样式
  &.has-sidebar {
    left: $base-sidebar-width;

    // 侧边栏收起时
    .sidebar-collapse & {
      left: 54px;
    }

    // 移动端
    .mobile & {
      left: 0;
    }
  }

  .btn-wrapper {
    max-width: 1200px;
    height: 100%;
    margin: 0 auto;
    padding: 12px 20px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;

    // 按钮样式
    :deep(.el-button) {
      margin: 0 8px;
      padding: 12px 25px;
      font-size: 14px;
      transition: all 0.3s;

      &:hover {
        transform: translateY(-2px);
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
      }
    }

    :deep(.el-button--primary) {
      &:hover {
        box-shadow: 0 2px 12px rgba(64, 158, 255, 0.3);
      }
    }
  }
}
</style>
